<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

//@TODO Añadir logs
class Links{
	
	var $ci;
	
	function Links(){
		$this->ci = &get_instance();

		$this->ci->load->model("Link_Model", "Links");
	}
	
}


 
 
// /**
// * Retrieve client information and save it into an array
// */
//$client_info = array ();
//
///**
// * Regular expression for a valid IP address
// */
//$IP_EXPRESSION = "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/";
//
//
///**
// * Get IP address of current visitor
// */
//$client_info['IP'] = (!empty ($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ((!empty ($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : @ getenv ('REMOTE_ADDR'));
//
//
///**
// * Get alternate IP address of current visitor,
// * like IP address behind a proxy
// */
//if (isset ($_SERVER['HTTP_CLIENT_IP']))
//{
//   $client_info['IP_BEHIND_PROXY'] = $_SERVER['HTTP_CLIENT_IP'];
//}
//elseif (isset ($_SERVER['HTTP_X_FORWARDED_FOR']))
//{
//   /**
//    * This gathered IP address is probably behind a proxy
//    * Do not rely on this and it doesn't make sense to block the whole proxy
//    */
//   preg_match_all ($IP_EXPRESSION.'s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches);
//
//
//   /**
//    * IP's defined by RFC 1918 are not saved
//    * http://rfc.net/rfc1918.html
//    */
//   foreach ($matches[0] as $IP)
//   {
//      if (!preg_match ("/^(10|172\.16|192\.168)\./", $IP))
//      {
//         $client_info['IP_BEHIND_PROXY'] = $IP;
//         break;
//      }
//   }
//}
//else
//{
//   $client_info['IP_BEHIND_PROXY'] = '';
//}
//
//
///**
// * Get the internet host name corresponding to a given IP address
// */
//$client_info['HOSTNAME'] = @ gethostbyaddr ($client_info['IP']);
//
//
///**
// * Contents of the User-Agent: header from the current request, if there is one
// */
//$client_info['USER_AGENT'] = (!empty ($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
//
//
///**
// * The address of the page (if any) which referred the user agent to the current page
// */
///*$client_info['query_from'] = $_SERVER['HTTP_REFERER'];*/
//
//
///**
// *The port being used on the user's machine to communicate with the web server
// */
//$client_info['PORT'] = (!empty ($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : '');
//
//
///**
// * The URI which was given in order to access this page
// */
//if ($_SERVER['REQUEST_URI'] || $_ENV['REQUEST_URI'])
//{
//   $client_info['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_ENV['REQUEST_URI'];
//}
//else
//{
//   if ($_SERVER['PATH_INFO'] || $_ENV['PATH_INFO'])
//      $client_info['REQUEST_URI'] = ($_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : $_ENV['PATH_INFO']);
//   elseif ($_SERVER['REDIRECT_URL'] || $_ENV['REDIRECT_URL'])
//      $client_info['REQUEST_URI'] = ($_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_ENV['REDIRECT_URL']);
//   else
//      $client_info['REQUEST_URI'] = ($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']);
//
//   if ($_SERVER['QUERY_STRING'] || $_ENV['QUERY_STRING'])
//      $client_info['REQUEST_URI'] .= '?'.($_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']);
//}
//
///**
// * The query string, if any, via which the page was accessed
// */
//$client_info['QUERY_STRING'] = str_replace ('&amp;amp;', '&amp;', urldecode ($_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : @ getenv ('QUERY_STRING')));
//
//
///**
// * Clean and repair client information
// */
//$client_info['IP']              = preg_replace ("{$IP_EXPRESSION}", "\\1.\\2.\\3.\\4", $client_info['IP']);
//$client_info['IP_BEHIND_PROXY'] = preg_replace ("{$IP_EXPRESSION}", "\\1.\\2.\\3.\\4", $client_info['IP_BEHIND_PROXY']);
//$client_info['REQUEST_URI']     = str_replace ('&amp;', '&', $client_info['REQUEST_URI']);
//$client_info['QUERY_STRING']    = str_replace ('&amp;', '&', $client_info['QUERY_STRING']);



/******** Tratamos el usuario que ha entrado *****/

//$id = ( isset ($_REQUEST['id']) ? trim ($_REQUEST['id']) : (isset ($_REQUEST['ID']) ? trim ($_REQUEST['ID']) : 0) );
//
//$id = preg_replace ('`(id[_]?)`', '', $id);
//$id = (preg_match ('`^[\d]+$`', $id) ? intval ($id) : 0);
//
//if ($id)
//{
//   $HitInfo = $db->GetRow("SELECT * FROM `{$tables['hitcount']['name']}` WHERE `LINK_ID` = ".$db->qstr($id)." AND `IP` = ".$db->qstr($client_info['IP']));
//
//   if (!empty ($HitInfo))
//   {
//      $current_time = date ('Y/m/d H:i:s');
//      $SecondsDiff  = dateTimeDifference($current_time, $HitInfo['LAST_HIT']);
//      $Diff         = second2hour($SecondsDiff);
//
//      if ($Diff > LIMIT_HITS_TIME)
//      {
//         $db->Execute("UPDATE `{$tables['link']['name']}` SET `HITS` = `HITS` + 1 WHERE `ID` = ".$db->qstr($id));
//         $where = '`ID` = '.$db->qstr($HitInfo['ID']);
//         $HitInfo['LAST_HIT'] = $current_time;
//         $db->AutoExecute($tables['hitcount']['name'], $HitInfo, 'UPDATE', $where);
//      }
//   }
//   else
//   {
//      $db->Execute("UPDATE `{$tables['link']['name']}` SET `HITS` = `HITS` + 1 WHERE `ID` = ".$db->qstr($id));
//      $HitInfo['LINK_ID'] = $id;
//      $HitInfo['IP']      = $client_info['IP'];
//      $db->AutoExecute($tables['hitcount']['name'], $HitInfo, 'INSERT', false);
//   }
//
//   unset ($HitInfo, $current_time, $Diff, $SecondsDiff);
//}